<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username" />
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password" />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="form.description" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="onCancel">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { add } from '@/api/user'

export default {
  data() {
    return {
      form: {
        username: '',
        name: '',
        password: '',
        mobile: '',
        description: ''
      }
    }
  },
  methods: {
    onSubmit() {
      //this.$message('submit!')
      add(this.form).then(response => {
        if(response.code === 20000){
          this.$message({
            message: '添加成功',
            type: 'success'
          })
          this.form = {
            username: '',
            name: '',
            password: '',
            mobile: '',
            description: ''
          }
        } else {
          this.$message({
            message: '添加失败',
            type: 'error'
          })
        }
        this.listLoading = false
      })
    },
    onCancel() {
      this.$message('已清空')
      this.form = {
        username: '',
        name: '',
        password: '',
        mobile: '',
        description: ''
      }
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

